﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MVCnExt.Web.UI.Ext
{
    public static class ExtIEnumerable
    {
        public static void Each<TSource>(this IEnumerable<TSource> source, Action<TSource> action)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (action == null)
            {
                return;
            }
            foreach (TSource item in source)
            {
                action(item);
            }
        }

        public static void EachIndex<TSource>(this IEnumerable<TSource> source, Action<int> action)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (action == null)
            {
                return;
            }
            int i = 0;
            IEnumerator<TSource> enumerator = source.GetEnumerator();
            while (enumerator.MoveNext())
            {
                action(i++);
            }
        }

    }
}
